Skip to content

gh-155315: Fix marshal round-trip of shared frozendict references - #155316

Merged
serhiy-storchaka merged 2 commits into
python:mainfrom
tonghuaroot:frozendict-marshal-ref
Aug 17, 2026
Merged

gh-155315: Fix marshal round-trip of shared frozendict references#155316
serhiy-storchaka merged 2 commits into
python:mainfrom
tonghuaroot:frozendict-marshal-ref

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

The TYPE_FROZENDICT reader reserved a reference slot with r_ref_reserve but
never filled it with r_ref_insert, so a frozendict referenced more than once
in the marshalled data failed to load with ValueError: bad marshal data (invalid reference). This mirrors the TYPE_FROZENSET reader, which already
calls r_ref_insert.

The TYPE_FROZENDICT reader reserved a reference slot but never filled it with
r_ref_insert, unlike TYPE_FROZENSET, so a frozendict referenced more than once
failed to load with ValueError.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but please remove the excessive comment.

Comment thread Python/marshal.c Outdated
}
if (type == TYPE_FROZENDICT && v != NULL) {
Py_SETREF(v, PyFrozenDict_New(v));
/* frozendicts use delayed reference registration (like

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is redundant. There are no such comments for frozenset, etc.

@serhiy-storchaka serhiy-storchaka added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Aug 16, 2026
@serhiy-storchaka

Copy link
Copy Markdown
Member

And please move NEWS to Core_and_Builtins.

@tonghuaroot

Copy link
Copy Markdown
Contributor Author

Done in 21bc04f: dropped the comment and moved the NEWS to Core_and_Builtins.

@serhiy-storchaka
serhiy-storchaka merged commit b6c11fe into python:main Aug 17, 2026
54 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @tonghuaroot for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Aug 17, 2026

Copy link
Copy Markdown

GH-155945 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants